package com.punai.dataanalysis.epdatakb.constants;

import cn.hutool.core.util.StrUtil;
import com.punai.dataanalysis.epdatakb.bo.CbsResBo;
import com.punai.dataanalysis.epdatakb.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DataKbConstants {

    private static final Logger log = LoggerFactory.getLogger(DataKbConstants.class);

    public enum DATA_ANALYSYS_ENUM_TABS_TYPE {


        JTCZFX_QFYCBZC("JTCZFX","qfycbzc","集团产值分析-全费用成本组成", IDataAnalysisJtczQfycbzcService.class),
        JTCZFX_TJDWZBNQFYCBBL("JTCZFX","tjdwzbnqfycbbl","集团产值分析-各单位工程全费用成本指标分析", IDataAnalysisJtczTjdwzbnqfycbblService.class),
        JTCZFX_TJDWCLFZBMX("JTCZFX","tjdwclfzbmx","集团产值分析-土建单位材料费成本指标分析", IDataAnalysisJtczTjdwclfzbmxService.class),
        JTCZFX_TJDWGFFZBMX("JTCZFX","tjdwgffzbmx","集团产值分析-土建单位人工费成本指标分析", IDataAnalysisJtczTjdwgffzbmxService.class),
        JTCZFX_ZYLQDWQFYCBZBMX("JTCZFX","zylqdwqfycbzbmx","集团产值分析-路桥单位材料费成本指标分析", IDataAnalysisJtczZylqdwqfycbzbmxService.class),
        JTCZFX_ZYAZDWQFYCBZBMX("JTCZFX","zyazdwqfycbzbmx","集团产值分析-安装单位材料费成本指标分析", IDataAnalysisJtczZyazdwqfycbzbmxService.class),

        JTQFYCBFX_QFYCBZC("JTQFYCBFX","qfycbzc","集团产值分析-全费用成本组成", IDataAnalysisQfycbzcService.class),
        JTQFYCBFX_TJDWZBNQFYCBBL("JTQFYCBFX","tjdwzbnqfycbbl","集团产值分析-土建单位占本年全费用成本比例", IDataAnalysisTjdwzbnqfycbblService.class),
        JTQFYCBFX_TJDWZYCLFZQFYCBBL("JTQFYCBFX","tjdwzyclfzqfycbbl","集团产值分析-土建单位主要材料费占全费用成本比例", IDataAnalysisTjdwzyclfzqfycbblService.class),
        JTQFYCBFX_TJDWRGFZBNQFYCBBL("JTQFYCBFX","tjdwrgfzbnqfycbbl","集团产值分析-土建单位人工费占本年全费用成本比例", IDataAnalysisTjdwrgfzbnqfycbblService.class),
        JTQFYCBFX_ZYDWZBNQFYCBBL("JTQFYCBFX","zydwzbnqfycbbl","集团产值分析-专业单位占本年全费用成本比例", IDataAnalysisZydwzbnqfycbblService.class),

        /** 年度 */
        NDGCLPDQKHZB("NDGCLPDQKHZB","*","年度工程量盘点情况汇总表", IDataAnalysisNdgclpdqkhzbService.class),
        NDGCCBQKHZB("NDGCCBQKHZB","*","年度工程成本情况汇总表", IDataAnalysisNdgccbqkhzbService.class),
        NDJSGCXMSJFXHZB("NDJSGCXMSJFXHZB","*","年度建设工程项目成本数据分析汇总表", IDataAnalysisNdjsgcxmsjfxhzbService.class),
        CBJXKHZB("CBJXKHZB","*","成本绩效考核表", IDataAnalysisCbjxkhService.class),
        JYCZBB("JYCZBB","*","经营产值报表", IDataAnalysisJyczbbService.class),

        SJXYFX("SJXYFX","*","三级效益分析", SjxyfxService.class),
        ;


        private String enumType;
        private String tabType;
        private String desc;
        // 执行器
        private Class<? extends DataAnalysisParentService> actuator;

        DATA_ANALYSYS_ENUM_TABS_TYPE(String enumType,String tabType,String desc,Class<? extends DataAnalysisParentService> actuator) {
            this.enumType = enumType;
            this.tabType = tabType;
            this.desc = desc;
            this.actuator = actuator;
        }


        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String getEnumType() {
            return enumType;
        }

        public void setEnumType(String enumType) {
            this.enumType = enumType;
        }

        public String getTabType() {
            return tabType;
        }

        public void setTabType(String tabType) {
            this.tabType = tabType;
        }

        public Class<? extends DataAnalysisParentService> getActuator() {
            return actuator;
        }

        public void setActuator(Class<? extends DataAnalysisParentService> actuator) {
            this.actuator = actuator;
        }

        /**
         * 获取执行器
         * @param enumType
         * @param tabType
         * @return
         */
        public static Class<? extends DataAnalysisParentService> getActuator(String enumType,String tabType) {
            for (DATA_ANALYSYS_ENUM_TABS_TYPE value : values()) {
                if (value.getEnumType().equals(enumType) &&
                        (value.getTabType().equals("*") || value.getTabType().equals(tabType))) {
                    return value.getActuator();
                }
            }
            return DataAnalysisParentService.class;
        }

    }


    public enum CBS_TABS_TYPE{
        TJ("土建","TJ","","",false,0,0),
        AZ("安装","AZ","","",false,0,0),
        TJ_RGF("土建","TJ01","","",false,0,0),
        AZ_RGF("安装","AZ01","","",false,0,0),
        TJ_CLF("土建","TJ02","","",false,0,0),
        AZ_CLF("安装","AZ02","","",false,0,0),
        FMMB("方木模板","TJ0202","","TJ02180201",false,0,0),
        ZCZLF("周材租赁费","TJ0218","TJ02180201","",false,0,0),
        TJZC("土建主材","TJ02","TJ0202","",true,1,13),
        TJFC("土建辅材","TJ02","","",true,14,17),
        AZZC("安装主材","AZ02","","",true,1,6),
        AZFC("安装辅材","AZ02","","",true,7,10);

        private String desc;
        private String sourceCode;
        /** 排除的code */
        private String excludeCode;
        /** 额外包含的code */
        private String includeCode;
        private Boolean range;
        private Integer rangeStart;
        private Integer rangeEnd;

        CBS_TABS_TYPE(String desc, String sourceCode, String excludeCode, String includeCode,boolean range,Integer rangeStart,Integer rangeEnd) {
            this.desc = desc;
            this.sourceCode = sourceCode;
            this.excludeCode = excludeCode;
            this.includeCode = includeCode;
            this.range = range;
            this.rangeStart = rangeStart;
            this.rangeEnd = rangeEnd;

        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String getSourceCode() {
            return sourceCode;
        }

        public void setSourceCode(String sourceCode) {
            this.sourceCode = sourceCode;
        }

        public String getExcludeCode() {
            return excludeCode;
        }

        public void setExcludeCode(String excludeCode) {
            this.excludeCode = excludeCode;
        }

        public String getIncludeCode() {
            return includeCode;
        }

        public void setIncludeCode(String includeCode) {
            this.includeCode = includeCode;
        }

        public Integer getRangeStart() {
            return rangeStart;
        }

        public void setRangeStart(Integer rangeStart) {
            this.rangeStart = rangeStart;
        }

        public Integer getRangeEnd() {
            return rangeEnd;
        }

        public void setRangeEnd(Integer rangeEnd) {
            this.rangeEnd = rangeEnd;
        }

        public Boolean getRange() {
            return range;
        }

        public void setRange(Boolean range) {
            this.range = range;
        }

        public CbsResBo getRangeCbsCodes() {
            CbsResBo resList = new CbsResBo();
            CBS_TABS_TYPE type = this;
            if (type.getRange()) {
                String sourceCode = type.getSourceCode();
                Integer rangeStart = type.getRangeStart();
                Integer rangeEnd = type.getRangeEnd();
                String excludeCode = type.getExcludeCode();
                for (int i = rangeStart; i <= rangeEnd ; i++) {
                    String s = sourceCode + getNumToStr(i);
                    if (!StrUtil.equals(s,excludeCode)) {
                        resList.getInclude().add(s);
                    }
                }
            } else {
                String sourceCode = this.getSourceCode();
                String excludeCode = this.getExcludeCode();
                if (StrUtil.isNotBlank(sourceCode)) {
                    resList.getInclude().add(sourceCode);
                }
                if (StrUtil.isNotBlank(excludeCode)) {
                    resList.getExclude().add(excludeCode);
                }
            }
            return resList;
        }


        private String getNumToStr(int i) {
            if (i > 10) {
                return "0" + i;
            }
            return ""+i;
        }

    }



}
